<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2021-07-16
  Time: 15:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css"  media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>

<form class="layui-form" action="">
    <div class="demoTable layui-form">
        <div class="layui-form-item">
            <div class="layui-inline" style="float: left">
                <label class="layui-form-label">时间范围</label>
                <div class="layui-input-inline" style="width: 300px">
                    <input type="text" class="layui-input" id="timeFrame" name="timeFrame" placeholder=" - ">
                </div>
            </div>
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <select name="branchid" lay-search="" id="branchTid">
                        <option value="">门店</option>
                    </select>
                </div>
            </div>
            <button type="button" class="layui-btn" lay-submit="" lay-filter="search">搜索</button>
        </div>
    </div>
</form>

<table class="layui-hide" id="test" lay-filter="test"></table>
<%--查询所有的出库详情表--%>
<div id="divEle3" style="display: none">
    <table id="demo3" lay-filter="test3" ></table>
    <%--<h1>总计：元</h1>--%>
</div>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <%--<button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>--%>
        <button class="layui-btn layui-btn-sm" lay-event="isAll">刷新</button>
    </div>
</script>

<script type="text/html" id="information">
    <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" lay-event="detailed">详细信息</button>
</script>

<script type="text/html" id="titleTpl">
    {{#  if(d.state == 1){ }}
    <button class="layui-btn layui-btn-warm layui-btn-sm" style="width: 70px">待审核</button>
    {{# } else if(d.state == 2){ }}
    <button class="layui-btn layui-btn-sm"  style="width: 70px">审核通过</button>
    {{#  } else { }}
    <button class="layui-btn layui-btn-danger layui-btn-sm"style="width: 70px">审核驳回</button>
    {{#  } }}
</script>


<script src="${pageContext.request.contextPath}/layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->

<script>
    layui.use(['table','form','jquery','layer','laydate'], function(){
        var table = layui.table;
        var form = layui.form;
        var $ = layui.jquery;
        var layer = layui.layer;
        var laydate = layui.laydate;

        //搜索填充
        window.onload=function (){ //页码加载完毕后执行的函数$(function(){})
            getAllBranch();
        }
        function getAllBranch(){
            $.ajax({
                url:"${pageContext.request.contextPath}/branch/findAll",
                typeP:"post",
                async:false,//ajax异步交互，async：false是同步提交
                success:function (result) {
                    var type=result.data;
                    var str="<option value=''>选择门店</option>";
                    for (var i = 0; i < type.length; i++) {
                        str+="<option value='"+type[i].branchid+"'>"+type[i].branchname+"</option>"
                    }
                    $("#branchTid").html(str);
                    $("#branch_id").html(str);
                    form.render('select'); //让form表单的select标签渲染
                },
                dataType:'json'
            });
        }

        //添加表单的搜索监听事件
        form.on('submit(search)',function(data){
            //表格数据重新渲染。
            table.reload('test',{
                page: {
                    curr: 1 //重新从第 1 页开始
                },
                where: { //按照什么进行查找
                    "timeFrame":data.field.timeFrame,
                    "branchid": data.field.branchid
                }
            })
        });

        //日期时间范围
        laydate.render({
            elem: '#timeFrame'
            ,type: 'datetime'
            ,range: true
        });

        table.render({
            elem: '#test'
            ,id:'test'
            ,url:'${pageContext.request.contextPath}/inventory/getAllFrmLoss'
            ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            ,title: '盘点审核表'
            ,text:{
                none:"暂无盘点审核信息～"
            }
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field:'invenid', title:'盘点编号',fixed: 'left'}
                ,{field:'invenstaffname', title:'报损员',templet: function (data) {
                        return data.invenstaff==null?"":data.invenstaff.staffname;
                    }}
                /*,{field:'inventime', title:'盘点时间'}*/
                ,{field:'examstaffname', title:'批准人',templet: function (data) {
                        return data.examstaff==null?"":data.examstaff.staffname;
                    }}
                ,{field:'examtime', title:'报损时间'}
                /*,{field:'state', title:'审核状态',templet:'#titleTpl'}*/
                ,{field:'branchname', title:'所属分店',templet: function (data) {
                        return data.branch==null?"":data.branch.branchname;
                    }}
                ,{field:'information', title:'详情',templet: '#information'}
            ]]
            ,page:true,//开启分页
            limit:5,//默认每页显示的条数
            limits:[5,10,15,20],//自定义分页条数的选择
        });

        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckData':
                    var data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：'+ data.length + ' 个');
                    break;
                case 'isAll':
                    table.reload('tb')
                    break;
                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
            };
        });

        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            console.log(obj)
            if(obj.event === 'detailed'){
                layer.open({
                    type: 1,
                    content: $("#divEle3"), //这里content是一个普通的String
                    area: ['780px' ,'400px'],
                    offset: 't'
                });

                table.render({
                    id:"test3",
                    //elem element 元素---》表格的容器
                    elem: '#demo3'//table标签的id属性值
                    //,height: 312//整个表格的高度
                    ,url: '${pageContext.request.contextPath}/inventory/getInventoryGoods' //数据接口
                    ,cols: [[ //表头
                        {type: 'checkbox', fixed: 'left'}
                        ,{field: 'lid', title: '报损详情ID'}
                        ,{field: 'invenid', title: '盘点表id',hide:true}
                        ,{field: 'goodsid', title: '商品ID',hide:true}
                        ,{field: 'goodsname', title: '商品名'}
                        ,{field: 'invennum', title: '盘点数量'}
                        ,{field: 'lossnum', title: '报损数量'}
                    ]],
                    page:true,//开启分页
                    limit:5,//默认每页显示的条数
                    limits:[5,10,15,20],//自定义分页条数的选择
                    where:{
                        invenid:data.invenid
                    }
                });
            }
        });
    });
</script>

</body>
</html>
